package ar.com.coonocer.joy.mdg.templatehelpers;

import java.util.List;

import ar.com.coonocer.joy.mdg.xmi.core.Class;
import ar.com.coonocer.joy.mdg.xmi.core.ModelElement;
import ar.com.coonocer.joy.mdg.xmi.core.Namespace;
import ar.com.coonocer.joy.mdg.xmi.model.Package;

public class ClassUtil {

	static public Class findClass(Package package_, String packageName, String className) {
		//
		List<ModelElement> ps = package_.getOwnedElement();
		for (ModelElement me : ps) {
			if (me instanceof Package) {
				Package p = (Package) me;
				//
				Class aux = findClass(p, packageName, className);
				if (aux != null) {
					return aux;
				}
			} else if (me instanceof Class) {
				Class clazz = (Class) me;
				//
				if (clazz.getName() != null && clazz.getName().equals(className)) {
					Namespace namespace = clazz.getNamespace();
					if (namespace != null && namespace.getName() != null && namespace.getName().equals(packageName)) {
						return clazz;
					}
				}
			}
		}
		//
		return null;
	}
}
